{% extends "svn.html" %}

{% block tabs %} {{ show_tabs() }} {% endblock %}

{% block css %}
	{{super()}}
   <style>
		#loading {
			left:50%;top:50%;margin-top:-55px;margin-left:-170px;
			width: 300px;
			padding: 20px;
			background: orange;
			color: white;
			text-align: center;
			display: none;
			position:absolute;
		}
	</style>
{% endblock css %}

{% block clientscript %}
	{{super()}}
	<script>
		$(document).ready(function(){
			$('#iframe_page').load(function() {
				$('#loading').hide();
			});
		});
		function edit_repository(id) {
		    $('#dlg').dialog({
						title: '仓库管理',
						width: 370,
						height: 320,
						closed: false,
						cache: false,
						//href: '?op=bsp&id=90',
						modal: true
					});
				   $('#dlg').dialog('refresh','/edit_repository'+(id?'/'+id:''));
		}
		function del_repository(id) {
         $.messager.confirm("确认", "确定要删除当前仓库吗?", function (r) {
                if (r) {
                    $.post("/del_repository/"+id,function(data,status){
                    		if (data=='1') {
                    			$('#gri').datagrid('reload');
                    		} else {
                    			alert(data);
                    		}
                         
                    });
                }
            });
		}
		function op_fmt(val,row) {
			return '[<a href="javascript:void(0)" onclick="edit_repository('+row.id+')">编辑</a>]&nbsp;&nbsp;'
					+'[<a href="javascript:void(0)" onclick="del_repository('+row.id+')">删除</a>]&nbsp;&nbsp;'
					+'[<a href="javascript:void(0)" onclick="deploy_repository('+row.id+')">部署</a>]&nbsp;&nbsp;'
					+'[<a href="javascript:void(0)" onclick="set_hook('+row.id+')">设置HOOK</a>]'
		}
		function deploy_repository(id) {
			var url='/deploy_repository/'+id;
			$('#loading').show();
			$('#iframe_page').attr('src',url);
			$('#dlg_deploy').dialog({  
				width: 780,  
				height: 550
			});  
			$('#dlg_deploy').dialog('open');
		}
		function set_hook(id) {
         $.messager.confirm("确认", "将覆盖原来的post_commit,确定吗?", function (r) {
                if (r) {
                    $.post("/set_hook/"+id,function(data,status){
                    		if (data=='1') {
                    			alert('设置成功!');
                    		} else {
                    			alert(data);
                    		}
                         
                    });
                }
            });
		}
	</script>
{% endblock clientscript%}

{% block work_content %}
	 <div id="tb" style="padding:3px">
	    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="edit_repository()">添加仓库</a>
    </div>
    {% from "snippet.html" import render_field %}
    <div id="dlg" closed="true" class="easyui-dialog" data-options="buttons: [{
            text:'确定',
            iconCls:'icon-ok',
            handler:function(){
                $.ajax({
                    type: 'post',
                    url: $('#form_post').attr('action'),
                    data:$('#form_post').serialize(),
                    dataType: 'text',
                    success: function(data,textStatus){
                        if (data=='1'){
                            $('#gri').datagrid('reload');
                            $('#dlg').dialog('close');
                        } else {
                            $.messager.alert('错误',data,'error');
                        }

                    },
                    error: function(err){
                        //请求出错处理
                        $.messager.alert('错误','操作失败,请稍后重试!','error');
                    }
                });
            }
        },{

            text:'取消',
            iconCls:'icon-cancel',
            handler:function(){
                $('#dlg').dialog('close');
            }
        }]">
    </div>
    <div id="dlg_deploy" title="部署设置" closed="true" modal="true" cache="false" 
    	class="easyui-dialog" data-options="
    	buttons: [{
            text:'关闭',
            iconCls:'icon-cancel',
            handler:function(){
                $('#dlg_deploy').dialog('close');
            }
        }]">
        <div id='loading'>页面正在加载,请稍等...</div>
        <iframe id='iframe_page' frameborder='0' scrolling='no'  width="760px" height="470px" src=""></iframe>
    </div> 
    <div class='grid'>
	    <table id="gri" class="easyui-datagrid" style="height:600px"
	            url="{{ url_for('qry_repository_data') }}"
	            title=""
	            toolbar="#tb"
	            singleSelect="true"
	            pageSize="20"
	            fitColumns="true"
	            rownumbers="true" pagination="true">
	        <thead>
	            <tr>
	                <th field="name" width="20">仓库名称</th>
						 <th field="remark" width="30">备注</th>
						 <th field="op" formatter="op_fmt" width="20">操作</th>
	            </tr>
	        </thead>
	    </table>
    </div>
{% endblock %}